package com.bgl.mall.controller.portal;

import com.bgl.mall.common.ServerResponse;
import com.bgl.mall.service.IProductService;
import com.bgl.mall.vo.ProductDetailVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BGL
 * @date 2017/7/3
 */
@Api(tags = "门户商品相关接口")
@RestController
@RequestMapping("/product/")
public class ProductController {

    @Autowired
    private IProductService productService;

    @ApiOperation("根据商品id查询商品详情")
    @PostMapping("detail.do")
    public ServerResponse<ProductDetailVo> getDetail(Integer productId){
        return productService.getProductDetail(productId);
    }

    @ApiOperation("分页查询商品列表")
    @PostMapping("list.do")
    public ServerResponse<PageInfo> list(@RequestParam(value = "keyword", required = false)String keyword,
                                         @RequestParam(value = "categoryId", required = false)Integer categoryId,
                                         @RequestParam(value = "pageNum", defaultValue = "1")int pageNum,
                                         @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,
                                         @RequestParam(value = "orderBy", defaultValue = "") String orderBy){
        return productService.getProductByKeywordCategory(keyword, categoryId, pageNum, pageSize, orderBy);
    }
}
